#include "UapStateBase.h"
#include "UapGlobals.h"
#include "Trace.h"

namespace tsc
{
namespace sgw
{

using namespace tsc::common;

/*******************************************************************************
 *
 * Constructor
 *
 ******************************************************************************/
UapStateBase::UapStateBase(const char* name) :
    StateBase(name)
{

} // UapStateBase::UapStateBase

/*******************************************************************************
 *
 * Destructor
 *
 ******************************************************************************/
UapStateBase::~UapStateBase()
{

} // UapStateBase::~UapStateBase

//===================================================================
void UapStateBase::handleEventUapConnectionReq(
	UapGenerator* uapGen,
	UapEventConnectionReq* event,
	EventData*& eventData)
{
    TRACE_ERROR(STR("Event UapEventConnectionReq not handled in state: %s",
                     getName()));
    EventData::deleteEvent(eventData);
}

//===================================================================
void UapStateBase::handleEventUapConnectionReleaseReq(
	UapGenerator* uapGen,
	UapEventConnectionReleaseReq* event,
    EventData*& eventData)
{
    TRACE_ERROR(STR("Event UapEventConnectionReleaseReq not handled in state: %s",
                     getName()));
    EventData::deleteEvent(eventData);
}

//===================================================================
void UapStateBase::handleEventUapMediaBearerSetupReq(
    UapGenerator* uapGen,
    UapEventMediaBearerSetupReq* event,
    EventData*& eventData)
{
    TRACE_ERROR(STR("Event UapEventMediaBearerSetupReq not handled in state: %s",
                     getName()));
    EventData::deleteEvent(eventData);
}

//===================================================================
void
UapStateBase::handleEventGapMediaBearerSetupCfm(
    UapGenerator* uapGen,
    UapEventGapMediaBearerSetupCfm* event,
    EventData*& eventData)
{
    TRACE_ERROR(STR("Event UapEventGapMediaBearerSetupCfm not handled in state: %s",
                     getName()));
    EventData::deleteEvent(eventData);
}

//===================================================================
void
UapStateBase::handleEventGapMediaBearerSetupRej(
    UapGenerator* uapGen,
    UapEventGapMediaBearerSetupRej* event,
    EventData*& eventData)
{
    TRACE_ERROR(STR("Event UapEventGapMediaBearerSetupRej not handled in state: %s",
                     getName()));
    EventData::deleteEvent(eventData);
}

//===================================================================
void
UapStateBase::handleEventGapMediaTransmissionFinishedInd(
    UapGenerator* uapGen,
    UapEventGapMediaTransmissionFinishedInd* event,
    EventData*& eventData)
{
    TRACE_ERROR(STR("Event UapEventGapMediaTransmissionFinishedInd not handled in state: %s",
                     getName()));
    EventData::deleteEvent(eventData);
}

//===================================================================
void
UapStateBase::handleEventT643Expired(
    UapGenerator* uapGen,
    UapEventT643Expired* event,
    EventData*& eventData)
{
    TRACE_ERROR(STR("Event UapEventT643Expired not handled in state: %s",
                     getName()));
    EventData::deleteEvent(eventData);
}

//===================================================================
void
UapStateBase::handleEvent(
    common::Generator*  generator,
    common::EventData*& eventData)
{
    if (!eventData)
    {
        return;
    }

    switch (eventData->sigNo())
    {
    case UAP_CONNECTION_REQ:
    {
        handleEventUapConnectionReq(
                static_cast<UapGenerator*>(generator),
                static_cast<UapEventConnectionReq*>(eventData),
                eventData);
    }
    break;

    case UAP_CONNECTION_RELEASE_REQ:
    {
        handleEventUapConnectionReleaseReq(
                static_cast<UapGenerator*>(generator),
                static_cast<UapEventConnectionReleaseReq*>(eventData),
                eventData);
    }
    break;

    case UAP_MEDIA_BEARER_SETUP_REQ:
    {
        handleEventUapMediaBearerSetupReq(
                static_cast<UapGenerator*>(generator),
                static_cast<UapEventMediaBearerSetupReq*>(eventData),
                eventData);
    }
    break;

    case UAP_GAP_MEDIA_BEARER_SETUP_CFM:
    {
        handleEventGapMediaBearerSetupCfm(
                static_cast<UapGenerator*>(generator),
                static_cast<UapEventGapMediaBearerSetupCfm*>(eventData),
                eventData);
    }
    break;

    case UAP_GAP_MEDIA_BEARER_SETUP_REJ:
    {
        handleEventGapMediaBearerSetupRej(
                static_cast<UapGenerator*>(generator),
                static_cast<UapEventGapMediaBearerSetupRej*>(eventData),
                eventData);
    }
    break;

    case UAP_GAP_MEDIA_TRANSMISSION_FINISHED_IND:
    {
        handleEventGapMediaTransmissionFinishedInd(
                static_cast<UapGenerator*>(generator),
                static_cast<UapEventGapMediaTransmissionFinishedInd*>(eventData),
                eventData);
    }
    break;

    case UAP_T643_EXPIRED:
    {
        handleEventT643Expired(
                static_cast<UapGenerator*>(generator),
                static_cast<UapEventT643Expired*>(eventData),
                eventData);
    }
    break;

    default:
        TRACE_ERROR(STR("Event:sigNo=0x%x not handled in switch",
                        eventData->sigNo()));
        EventData::deleteEvent(eventData);
    }
}

} // namespace sgw
} // namespace tsc
